package com.cxb.view;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.cxb.R;

public class ScreenCoverDialog extends LinearLayout  {

	private WindowManager windowManager;
	private WindowManager.LayoutParams layoutParams;
	private View ll_stop_connect;
	private static boolean isShowing = false;

	public ScreenCoverDialog(Context context) {
		super(context);
	
		LayoutInflater.from(getContext()).inflate(R.layout.cover_screen, this);
		windowManager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		layoutParams = new WindowManager.LayoutParams();
		layoutParams.width = 300;
		layoutParams.height = 100;
		layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
		layoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
		layoutParams.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
				| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
				| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
		layoutParams.systemUiVisibility = SYSTEM_UI_FLAG_LOW_PROFILE;

		this.setKeepScreenOn(true);

	}

	public void show() {
		try {
			
			if (!isShowing) {
				isShowing = true;
				windowManager.addView(this, layoutParams);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void dimiss() {
		try {
			
			if (isShowing) {
				windowManager.removeView(this);
				isShowing = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}



	public interface OnStopConnectListener {
		void onDisConnect();
	}

}
